package com.isunland.managesystem.adapter;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.RDistributionSub;
import com.isunland.managesystem.ui.CompanyForumPictureActivity;
import com.isunland.managesystem.ui.CompanyForumPictureFragment;
import com.isunland.managesystem.utils.MyDateUtil;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/4/5 15:01
 */

public class SignDeliveryAdapter extends BaseButterKnifeAdapter<RDistributionSub> {

  @SuppressWarnings("unused")
  public SignDeliveryAdapter(BaseVolleyActivity context, ArrayList<RDistributionSub> objects) {
    super(context, objects);
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_delivery_sign;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override
  protected void initView(final RDistributionSub item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;
    //noinspection deprecation
    holder.tvSignTimeItemAttendanceList.setBackgroundColor(
        context.getResources().getColor(R.color.primary));
    holder.tvSignTimeItemAttendanceList.setText(MyDateUtil.format(item.getRegDate(), "HH:mm"));
    holder.tvDateItemAttendanceList.setText(MyDateUtil.format(item.getRegDate()));
    holder.tvSignLocationItemAttendanceList.setText(
        MyStringUtil.isEmpty(item.getSignLocaltion()) ? context.getString(R.string.noLocation)
            : item.getSignLocaltion());
    holder.tvSignRemarkItemAttendanceList.setText(item.getRemark());
    holder.ivPhoto.setVisibility(
        MyStringUtil.isEmpty(item.getSignPhoto()) ? View.GONE : View.VISIBLE);
    holder.ivPhoto.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        String filePath = item.getSignPhoto();
        Intent intent = new Intent(context, CompanyForumPictureActivity.class);
        intent.putExtra(CompanyForumPictureFragment.EXTRA_PICTUREA, filePath);
        intent.putExtra(CompanyForumPictureFragment.TYPE, CompanyForumPictureFragment.TYPEA);
        context.startActivity(intent);
      }
    });
  }

  protected class ViewHolder extends BaseViewHolder {

    @BindView(R.id.tv_SignTime_ItemAttendanceList) TextView tvSignTimeItemAttendanceList;
    @BindView(R.id.tv_date_ItemAttendanceList) TextView tvDateItemAttendanceList;
    @BindView(R.id.tv_SignLocation_ItemAttendanceList) TextView tvSignLocationItemAttendanceList;
    @BindView(R.id.tv_SignRemark_ItemAttendanceList) TextView tvSignRemarkItemAttendanceList;
    @BindView(R.id.iv_photo) ImageView ivPhoto;

    ViewHolder(View view) {
      super(view);
      //点击事件

    }
  }
}
